package com.fausto.learnimprint

import com.baomidou.mybatisplus.extension.plugins.pagination.Page
import com.fausto.learnimprint.core.mapper.RoleMapper
import com.fausto.learnimprint.core.mapper.UserMapper
import com.fausto.learnimprint.core.mapper.UserRoleMapper
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Test
import org.springframework.beans.factory.annotation.Autowired

class MybatisPlusTest(
) : BlogApplicationTests() {

    @Autowired
    lateinit var userMapper: UserMapper

    @Autowired
    lateinit var userRoleMapper: UserRoleMapper

    @Autowired
    lateinit var roleMapper: RoleMapper

    @Test
    fun userTest() {
        Assertions.assertNotNull(
            userMapper.selectByMap(
                mapOf(
                    "user_name" to "admin"
                )
            )
        )
    }

    @Test
    fun roleTest() {
        val roles = userRoleMapper.selectByMap(mapOf("user_id" to 1))
        roles.forEach {
            println(roleMapper.selectById(it.roleId))
        }
    }

    /**
     *      测试分页插件
     */
    @Test
    fun pageTest() {
        userMapper.selectPage(
            Page<com.fausto.learnimprint.core.model.entity.User>(1, 3),
            null
        ).records.forEach(::println)

    }


}